package zxs.sino.elite.hub.controller;

import java.io.IOException;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zxs.sino.elite.hub.model.form.ArticleForm;
import zxs.sino.elite.hub.model.vo.app.ArticleVo;
import zxs.sino.elite.hub.service.app.ArticleService;
import zxs.sino.elite.hub.utils.R;



/**
 * 文章表
 *
 * @author zhang
 * @email 15824760766@163.com
 * @date 2025-09-02 20:23:52
 */
@RestController
@RequestMapping("article")
@RequiredArgsConstructor
public class ArticleController {

    private final ArticleService articleService;

    /**
     * 信息
     */
    @RequestMapping("/info/{articleId}")
    public R info(@PathVariable("articleId") Long articleId){
        ArticleVo article = articleService.getArticle4ArticleId(articleId);

        return R.ok().put("article", article);
    }

    /**
     * 保存/修改博客
     */
    @RequestMapping("/saveOrUpdateArticle")
    public R save(@RequestBody ArticleForm article) throws IOException {
		articleService.saveOrUpdateArticle(article);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{articleId}")
    public R deleteArticle(@PathVariable("articleId") Long articleId) throws IOException {
        articleService.deleteArticle(articleId);

        return R.ok();
    }

}
